//
//  VBNavigationViewController.swift
//  VBo
//
//  Created by 赵世得 on 2016/10/22.
//  Copyright © 2016年 Zh. All rights reserved.
//

import UIKit

class VBNavigationViewController: UINavigationController,UIGestureRecognizerDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
    }
    
    @objc private func backClick(){
        popViewController(animated: true)
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        var title: String
        
        if childViewControllers.count > 0 {
            title = "返回"
            
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? ""
                
            }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(setImg: "navigationbar_back_withtext", title: title, target: self, action: #selector(backClick))
        }
        super.pushViewController(viewController, animated: true)
    }
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        return childViewControllers.count != 1
    }
}
